home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / swtools / generic / message.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  4.6 KB  |  194 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17.  
  18. #include <gl.h>
  19. #include <device.h>
  20. #include <unistd.h>
  21. #include "showcaseui.h"
  22. #include "generic.h"
  23.  
  24. /* This file implements the message() command that is called in various
  25.  * places to present messages and to ask for confirmation.  It happens 
  26.  * to use the Showcase libui.  If you don't like this code, toss this
  27.  * file out, but provide a routine called message that does the same
  28.  * sorts of things this one does.
  29.  */
  30.  
  31. static Button *ybut = 0, *nbut = 0, *cbut = 0;
  32. static long xmin, xmax, ymin, ymax;
  33.  
  34. extern long uiinited;    /* this is declared in pulldown.c */
  35.  
  36. long owid, newwid;
  37.  
  38. void createdialogarea()
  39. {
  40.     long screenx, screeny;
  41.     
  42.     screenx = getgdesc(GD_XPMAX);
  43.     screeny = getgdesc(GD_YPMAX);
  44.     xmin = xsize/2 - 300 + xorg;
  45.     ymin = ysize/2 - 55 + yorg;
  46.     if (xmin < 0) xmin = 0;
  47.     if (xmin + 600 >= screenx) xmin = screenx - 601;
  48.     if (ymin < 0) ymin = 0;
  49.     if (ymin + 110 >= screeny) ymin = screeny - 111;
  50.     xmax = xmin + 600;
  51.     ymax = ymin + 110;
  52.     prefposition(xmin, xmax, ymin, ymax);
  53.     noborder();
  54.     owid = winget();
  55.     newwid = winopen("dialog");
  56.     winset(newwid);
  57.     pushviewport();
  58.     savemat();
  59.     viewport(0, (short)(xmax-xmin), 0, (short)(ymax-ymin));
  60.     ortho2(-0.5, xmax-xmin+0.5, -0.5, ymax-ymin+0.5);
  61. }
  62.  
  63. void closedialogarea()
  64. {
  65.     popviewport();
  66.     restoremat();
  67.     winclose(newwid);
  68. }
  69.  
  70. static void drawbackground()
  71. {
  72.     uiWhite(); rectfi(0, 0, xmax-xmin, ymax-ymin);
  73.     setpattern(P_UISHADOW);
  74.     uiVyLtGray(); rectfi(0, 0, xmax-xmin, ymax-ymin);
  75.     setpattern(0);
  76.     uiBlack();
  77. }
  78.  
  79. static void drawconfirmmessage(char *s)
  80. {
  81.     long cheight;
  82.     drawbackground();
  83.     recti(0, 0, 600, 110);
  84.     recti(3, 3, 597, 107);
  85.     recti(4, 4, 596, 106);
  86.     cheight = 80;
  87.     while (*s) {
  88.         char *sptr = s;
  89.     cmov2i(20, cheight); cheight -= 18;
  90.     while (*sptr && *sptr != '\n') sptr++;
  91.     if (*sptr)  {
  92.         *sptr = 0; charstr(s); *sptr = '\n'; s = sptr+1;
  93.     } else {
  94.         charstr(s);
  95.         s = sptr;
  96.     }
  97.     }
  98.     if (ybut) drawbut(ybut);
  99.     if (nbut) drawbut(nbut);
  100.     if (cbut) drawbut(cbut);
  101.     swapbuffers();
  102. }
  103.  
  104. static void makeconfirmbuts(char *b1, char *b2,  char *b3)
  105. {
  106.     createdialogarea();
  107.     if (ybut) freebut(ybut); ybut = 0;
  108.     if (nbut) freebut(nbut); nbut = 0;
  109.     if (cbut) freebut(cbut); cbut = 0;
  110.     if (b1) {
  111.         ybut = newbut(100, 15, 170, 45);
  112.     loadbut(ybut, b1);
  113.     }
  114.     if (b2) {
  115.         nbut = newbut(200, 15, 270, 45);
  116.     loadbut(nbut, b2);
  117.     }
  118.     if (b3) {
  119.         cbut = newbut(300, 15, 370, 45);
  120.     loadbut(cbut, b3);
  121.     }
  122. }
  123.  
  124. long message(char *str, char *b1, char *b2,  char *b3)
  125. {
  126.     short val;
  127.     long dev, mx, my;
  128.     static inited = 0;
  129.  
  130.     if (!uiinited) {
  131.         uiinited = 1;
  132.     initui();
  133.     }
  134.     if (inited == 0) {
  135.         inited = 1;
  136.         initbut();
  137.     }
  138.     makeconfirmbuts(b1, b2, b3);
  139.     drawconfirmmessage(str);
  140.     if (ybut == 0) {
  141.     (void)sleep(3);
  142.     closedialogarea();
  143.     return 0;
  144.     }
  145.     while (1) {
  146.     dev = qread(&val);
  147.     switch (dev) {
  148.         case 0:
  149.             break;
  150.         case MOUSEX:
  151.         case MOUSEY:
  152.         mx = getvaluator(MOUSEX) - xmin;
  153.         my = getvaluator(MOUSEY) - ymin;
  154.         if (ybut) locatebut(ybut, mx, my);
  155.         if (nbut) locatebut(nbut, mx, my);
  156.         if (cbut) locatebut(cbut, mx, my);
  157.         break;
  158.         case LEFTMOUSE:
  159.         if (val == 0) break;
  160.         mx = getvaluator(MOUSEX)  - xmin;
  161.         my = getvaluator(MOUSEY)  - ymin;
  162.         if (ybut && inbut(ybut, mx, my))
  163.             if (pressbut(ybut, mx, my)) {
  164.                 closedialogarea();
  165.                 return 1;
  166.             }
  167.         if (nbut && inbut(nbut, mx, my))
  168.             if (pressbut(nbut, mx, my)) {
  169.                 closedialogarea();
  170.                 return 2;
  171.             }
  172.         if (cbut && inbut(cbut, mx, my))
  173.             if (pressbut(cbut, mx, my)) {
  174.                 closedialogarea();
  175.                 return 3;
  176.             }
  177.         break;
  178.         case REDRAW:
  179.             winpop();
  180.         drawconfirmmessage(str);
  181.         break;
  182.         case WINQUIT:
  183.         case WINSHUT:
  184.         closedialogarea();
  185.         return 0;
  186.         default:
  187.             if (dev == MOUSEX || dev == MOUSEY) break;
  188.         drawconfirmmessage(str);
  189.         break;
  190.     }
  191.     }
  192. }
  193.  
  194.